/**
 * @author wn
 * @date 2023/11/02 11:32:56
 * @description: 收货地址 API 接口
 */

import { request } from '@/utils/request'

enum Url {
	MemberAddress = '/member/address',
}

/**
 * 添加收货地址
 * @param data 添加收货地址 表单类型
 * @returns Promise<Any>
 */
export const addMemberAddressApi = (data: AddressParams) =>
	request({
		method: 'POST',
		url: Url.MemberAddress,
		data,
	})

/**
 * 获取收货地址列表
 * @returns Promise
 */
export const getMemberAddressListApi = () =>
	request<AddressItem[]>({
		method: 'GET',
		url: `${Url.MemberAddress}`,
	})

/**
 * 通过 id 获取 收货地址详情信息 -- 回显
 * @param id -- 修改按钮时传递过来
 * @returns Promise
 */
export const getMemberAddressByIdApi = (id: string) =>
	request<AddressItem>({
		method: 'GET',
		url: `${Url.MemberAddress}/${id}`,
	})

/**
 * 通过 id 修改收货地址
 * @param id -- 修改按钮时传递过来
 * @param data -- 表单校验数据
 * @returns Promise<Any>
 */
export const updateMemberAddressByIdApi = (id: string, data: AddressParams) =>
	request({
		method: 'PUT',
		url: `${Url.MemberAddress}/${id}`,
		data,
	})

/**
 * 通过 id 删除收货地址
 * @param id
 * @returns Promise<Any>
 */
export const deleteMemberAddressByIdApi = (id: string) =>
	request({
		method: 'DELETE',
		url: `${Url.MemberAddress}/${id}`,
	})
